package com.probox.modules.controller.customer;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.customer.LevelPrivilege;
import com.probox.common.entity.service.customer.ILevelPrivilegeService;
import com.probox.common.entity.vo.customer.LevelPrivilegeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * 自定义权益Controller
 *
 * @author zhusiyu
 * @date 2021-05-27
 */
@Api(value = "客户模块",tags={"等级权益后台操作接口"})
@RestController
@RequestMapping("/customer/levelPrivilege/privilege")
public class LevelPrivilegeController extends BaseController {
    @Autowired
    private ILevelPrivilegeService levelPrivilegeService;

    /**
     * 查询自定义权益列表
     */
    @ApiOperation(value="查询自定义权益列表")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:list")
    @GetMapping("/list")
    public TableDataInfo list(LevelPrivilege levelPrivilege) {
        startPage();
        List<LevelPrivilege> list = levelPrivilegeService.queryList(levelPrivilege);
        return getDataTable(list);
    }

    /**
     * 导出自定义权益列表
     */
    @ApiOperation(value="导出自定义权益列表")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:export")
    @Log(title = "自定义权益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LevelPrivilege levelPrivilege) throws IOException {
        List<LevelPrivilege> list = levelPrivilegeService.queryList(levelPrivilege);
        ExcelUtil<LevelPrivilege> util = new ExcelUtil<LevelPrivilege>(LevelPrivilege.class);
        util.exportExcel(response, list, "自定义权益数据");
    }

    /**
     * 获取自定义权益详细信息
     */
    @ApiOperation(value="获取自定义权益详细信息")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:query")
    @GetMapping(value = "/{privilegeUid}")
    public AjaxResult getInfo(@PathVariable("privilegeUid") Long privilegeUid) {
        return AjaxResult.success(levelPrivilegeService.selectLevelPrivilegeById(privilegeUid));
    }

    /**
     * 新增自定义权益
     */
    @ApiOperation(value="新增自定义权益")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:add")
    @Log(title = "自定义权益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LevelPrivilege levelPrivilege) {
        return toAjax(levelPrivilegeService.insertLevelPrivilege(levelPrivilege));
    }

    /**
     * 修改自定义权益
     */
    @ApiOperation(value="修改自定义权益")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:edit")
    @Log(title = "自定义权益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LevelPrivilege levelPrivilege) {
        return toAjax(levelPrivilegeService.updateLevelPrivilege(levelPrivilege));
    }

    /**
     * 删除自定义权益
     */
    @ApiOperation(value="删除自定义权益")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:remove")
    @Log(title = "自定义权益", businessType = BusinessType.DELETE)
    @DeleteMapping("/{privilegeUids}")
    public AjaxResult remove(@PathVariable Long[] privilegeUids) {
        return toAjax(levelPrivilegeService.deleteLevelPrivilegeByIds(privilegeUids));
    }

    /**
     * 修改权益状态
     */
    @ApiOperation(value="修改权益状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "privilegeUid", value = "权益ID",paramType = "bigint", required = true),
            @ApiImplicitParam(name = "status", value = "(状态 1有效 0无效)",paramType = "String", required = true),
    })
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:edit")
    @Log(title = "修改权益状态", businessType = BusinessType.UPDATE)
    @PutMapping("/updateCustomerStatus")
    public AjaxResult updateCustomerStatus(@RequestBody LevelPrivilege levelPrivilege) {
        return toAjax(levelPrivilegeService.updateLevelPrivilege(levelPrivilege));
    }

    /**
     * 查询权益具体等级使用情况
     */
    @ApiOperation(value="查询权益具体等级使用情况")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:list")
    @GetMapping("/privilegeLevelInfo/{privilegeName}")
    public AjaxResult privilegeLevelInfo(@PathVariable String privilegeName) {
        LevelPrivilegeVo levelPrivilegeVo = levelPrivilegeService.getprivilegeLevelInfo(privilegeName);
        return AjaxResult.success(levelPrivilegeVo);
    }

    /**
     * 查询权益信息
     */
    @ApiOperation(value="查询权益信息")
    @PreAuthorize(hasPermi = "levelPrivilege:privilege:list")
    @GetMapping("/privilegeInfo")
    public AjaxResult privilegeInfoList() {
        List<LevelPrivilege> privilegeInfoList = levelPrivilegeService.getprivilegeInfoList();
        return AjaxResult.success(privilegeInfoList);
    }


}
